package com.hyperfix.simulator.timer;

import com.hyperfix.simulator.senor.CombinationSenor;
import com.hyperfix.simulator.utils.SpringBeanUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.core.KafkaTemplate;

/**
 * @author JiangChunYu
 * 2024/3/14
 */
@Data
@EqualsAndHashCode
public class SysJob implements Runnable {
    private final Integer jobId;
    private final CombinationSenor senor;

    private static final Logger logger = LoggerFactory.getLogger(SysJob.class);

    public SysJob(Integer jobId, CombinationSenor senor) {
        this.jobId = jobId;
        this.senor = senor;
    }

    @Override
    public void run() {
        @SuppressWarnings("unchecked")
        KafkaTemplate<String,byte[]> kafkaTemplate = SpringBeanUtils.getBean(KafkaTemplate.class);
        byte[] data = senor.nextData();
        int station = data[0] >>> 1;
        switch (station) {
            case 1:
                kafkaTemplate.send("HC", "HC", data);
                break;
            case 2:
                kafkaTemplate.send("DW", "DW", data);
                break;
            default:
                break;
        }

    }
}
